/**
 * 导出所有的接口请求函数
 */
import base from './base'
import req from './req'
/**
 * 获取分类列表
 * @returns 
 */
export const getCategoryList=()=>req.get(base.categoryUrl);


/**
 * 获取首页轮播图
 * @returns 
 */
export const getBanner=()=>req.get(base.banerUrl);

/**
 * 首页主体--新鲜好物
 * @returns 
 */
export const getNew=()=>req.get(base.findNew);

/**
 * 首页主体--人气推荐
 * @returns 
 */
 export const getHot=()=>req.get(base.findhot);


 /**
 * 首页主体--产品区块
 * @returns 
 */
  export const getProducts=()=>req.get(base.product);
  
/**
 * 根据分类获取商品
 * @returns 
 */
export const getProductsByCategory = (category) => {
  console.log('调用 getProductsByCategory API');
  return req.post(base.productsByCategory, { category });
}

/**
 * 首页推荐商品
 * @returns 
 */
export const getSomeProducts = () => {
  console.log('调用 getSomeProduct API');
  return req.post(base.someProducts, {});
}

/**
 * 获取用户头像信息
 * @returns 
 */
export const getUserAvatar = (userId) => {
  return req.post(base.userAvatar, { userId });
}

/**
 * 获取用户详细信息
 * @returns 
 */
export const getUserProfile = () => {
  return req.post(base.userProfile);
}

/**
 * 更新用户信息（用于添加）
 * @param {Object} formData 包含用户信息的表单数据
 * @returns 
 */
export const updateUserProfile = (formData) => {
  return req.post(base.updateUserProfile, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

/**
 * 更新用户信息（用于修改）
 * @param {Object} userData 包含用户信息的JSON数据
 * @returns 
 */
export const updateUserId = (userData) => {
  return req.post(base.updateUserId, userData);
}

/**
 * 修改用户密码
 * @param {Object} data 包含用户名、当前密码和新密码的数据
 * @returns 
 */
export const updatePassword = (data) => {
  return req.post(base.updatePassword, data);
}

/**
 * 获取用户收货地址列表
 * @returns 
 */
export const getUserAddresses = () => {
  return req.get(base.getUserAddresses);
}

/**
 * 添加用户收货地址
 * @param {Object} addressData 地址信息
 * @returns 
 */
export const addUserAddress = (addressData) => {
  return req.post(base.addUserAddress, addressData);
}

/**
 * 删除用户收货地址
 * @param {Number} addressId 地址ID
 * @returns 
 */
export const deleteAddress = (addressId) => {
  return req.delete(`${base.deleteAddress}/${addressId}`);
}

/**
 * 添加商品到购物车
 * @param {Object} cartData 购物车数据，包括productId和quantity
 * @returns 
 */
export const addProductToCart = (cartData) => {
  return req.post(base.addProductToCart, cartData);
}

/**
 * 获取购物车商品列表
 * @returns 
 */
export const getCartItems = () => {
  return req.get(base.getCartItems);
}

/**
 * 更新购物车商品
 * @param {Number} cartId 购物车项ID
 * @param {Object} cartData 购物车数据，包括quantity等
 * @returns 
 */
export const updateCartItem = (cartId, cartData) => {
  return req.post(`${base.updateCartItem}/${cartId}`, cartData);
}

/**
 * 删除购物车商品
 * @param {Number} cartId 购物车项ID
 * @returns 
 */
export const deleteCartItem = (cartId) => {
  return req.delete(`${base.deleteCartItem}/${cartId}`);
}

/**
 * 同步商品库存
 * @param {Number} productId 商品ID
 * @returns 
 */
export const syncProductStock = (productId) => {
  return req.post('/api/home/products/syncStock', { productId });
}

/**
 * 创建订单
 * @param {Object} orderData 订单数据
 * @returns 
 */
export const createOrder = (orderData) => {
  return req.post('/api/pay/orders/create', orderData);
}

/**
 * 获取用户订单列表
 * @returns 
 */
export const getUserOrders = () => {
  return req.get('/api/pay/orders/list');
}

/**
 * 获取商家订单列表
 * @returns 
 */
export const getMerchantOrders = () => {
  return req.get('/api/pay/orders/merchant/list');
}

/**
 * 支付订单
 * @param {Number} orderId 订单ID
 * @returns 
 */
export const payOrder = (orderId) => {
  return req.post(`/api/pay/orders/updateStatus/${orderId}`, { status: 2 });
}

/**
 * 确认收货
 * @param {Number} orderId 订单ID
 * @returns 
 */
export const confirmReceipt = (orderId) => {
  return req.post(`/api/pay/orders/confirm/${orderId}`);
}

/**
 * 商家发货
 * @param {Number} orderId 订单ID
 * @returns 
 */
export const merchantShipOrder = (orderId) => {
  return req.post(`/api/pay/orders/ship/${orderId}`);
}

/**
 * 获取商家余额
 * @returns 
 */
export const getMerchantBalance = () => {
  return req.get('/api/pay/orders/merchant/balance');
}

/**
 * 修改商家密码
 * @param {Object} data 包含原密码和新密码的数据
 * @returns 
 */
export const updateMerchantPassword = (data) => {
  return req.post(base.updateMerchantPassword, data);
}

/**
 * 获取用户余额
 * @returns 
 */
export const getUserBalance = () => {
  return req.get('/api/pay/orders/user/balance');
}
